<!doctype html>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>商之联运营商后台</title>
  <meta name="description" content="这是一个form页面">
  <meta name="keywords" content="form">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="{:C('SUPPLIER_ADMIN_IMAGE')}favicon.png"> <link rel="apple-touch-icon-precomposed" href="{:C('SUPPLIER_ADMIN_IMAGE')}app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="{:C('SUPPLIER_ADMIN_CSS')}amazeui.min.css"/>
  <link rel="stylesheet" href="{:C('SUPPLIER_ADMIN_CSS')}admin.css">
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->
<!-- header start-->

<include file="Public:header"/>

<!-- header end-->
<div class="am-cf admin-main">
 <!-- sidebar start -->
   <include file="Public:menu"/>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content">

    <div class="am-cf am-padding">
      <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">订单管理</strong> / <small>订单列表</small></div>
    </div>
  <!-- 搜索条件start -->
  <form >
    <div class="am-g ">
      <div class="am-u-sm-12 am-u-md-4 search">
        <p><label>订单号：</label>&nbsp;&nbsp;&nbsp;<input type="text" name="ordersn" /> </p>
        <p><label>支付类型：</label>
        <select name="paytype">
          <option  value="99">请选择支付类型</option>
          <foreach name="paytype" item="type" key="key">
              <option value="{$key}">{$type}</option>
          </foreach>
        </select>
        </p>
        <p>
            <label>加盟商家：</label>
            <select name="shopid" style='width:50%'>
              <option  value="0">请选择商家</option>
              <foreach name='allshop' item='name' key='key'>
                <option  value="{$key}">{$name}</option>
              </foreach>
            </select>
            
        </p>
      </div>
      <div class="am-u-sm-12 am-u-md-4 search">
        <p><label>订单类型：</label>
        <select name="areatype">
            <option value="99">请选择订单类型 </option>
            <foreach name='areatype' item='type' key="key">
                <option value="{$key}">{$type} </option>
            </foreach>
        </select>
        </p>
        <p><label>订单状态：</label>
          <select name="orderstatus">
              <option value="99"> 请选择订单状态</option> 
            <foreach name="allstatus" item="status" key="key">
              <option value="{$key}">{$status}</option>
            </foreach>
            
          </select>
      </div>
      <div class="am-u-sm-12 am-u-md-4 search">
      
      <p>  开始时间： <input class="laydate-icon" id="start" style="width:200px; margin-right:10px;"  /> </p>
      <p>  结束时间： <input class="laydate-icon" id="end" style="width:200px;"/></p>
    
      
      </div>

    </div>
    
    <div class="am-g search"> 
      <P>
      <button class="putcsv"><span class="am-icon-line-chart"></span> 导出订单 </button>
      <button type="reset"><span class="am-icon-repeat"></span>重置</button>
      <button id="search"><span class="am-icon-search"></span>搜索</button> 
      </P>
    </div>
  <!-- 搜索条件end -->
</form>

    <div class="am-g">
      <div class="am-u-sm-12">

          <table class="am-table am-table-striped am-table-hover table-main ordertable">
            <thead>
              <tr>
                <th class="table-check"><input type="checkbox" id="checkAll" ></th>
                <th class="table-id">序号</th>
                <th class="table-title">订单号</th>
                <th class="table-title">订单数量</th>
                <th class="table-title">零售价</th>
                <th class="table-title">供货价</th>
               
                <th class="table-date">支付类型</th>
                <th class="table-date">经销商企业</th>
                <th class="table-date">创建时间</th>
                <th class="table-title">订单状态</th>
                <th class="table-title">订单区域</th>
                <th class="table-set">操作</th>
              </tr>
          </thead>
          <tbody >
            <foreach name="orders" item='order'>
            <tr>
              <td><input type="checkbox" name="subBox" value="{$order['orderid']}"></td>
              <td>{$order['orderid']}</td>
              <td> {$order['order_sn']}</td>
              <td>{$order['number']}</td>
              <td>{$order['price']}</td>
              <td>{$order['supperprice']}</td>
              <td>{$order.pay_type}</td>
              <td>{$order['companyname']}</td>
              <td>
                <if condition="$order.create_time neq 0 ">
          {$order.create_time}
                </if>
              </td>
              <td>{$order.allstatus}</td>
               <td>{$order.area}</td>
              <td>
                <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">
                    <span class="am-icon-pencil-square-o"></span><a href="{:U('Order/detail',array('id'=>$order['orderid']))}" >详情</a> 
                  </div>
                </div>
              </td>
            </tr>
            </foreach>
          </tbody>
        </table>
          
  

<div class="am-fr page">
    <ul class="am-pagination" >
      <li>共<label class="count"> {$pagearr['count']}</label> 条记录</li>
      <li>当前第 <label class="currentpage"> {$pagearr['page']} </label> 页</li>
     <!-- <li><label>每页&nbsp;</label><input type="text" size="2" id="pagesize" value="15" onkeypress="return listTable.changePageSize(event)"></li> -->
      <li><a href="javascript:pageajax('firpage')" class="firpage" value="1" >第一页</a></li>
      <li><a href="javascript:pageajax('prepage')" class="prepage" value="{$pagearr['page']-1}">上一页</a></li>
      <li><a href="javascript:pageajax('nexpage')" class="nexpage" value="{$pagearr['page']+1}">下一页</a></li>
      <li><a href="javascript:pageajax('laspage')" class="laspage" value="{$pagearr['totalpage']}">最末页</a></li>
     <!-- <li><input type="text" size="2" id="pageSize"class="am-input-group-sm" value="15"/ >&nbsp; <button class="am-btn-default am-btn-primary am-fr">GO</button> </li>-->
    </ul>
  </div>


      </div>

    </div>
  </div>
  <!-- content end -->
</div>
<footer>
  <hr>
  <p class="am-padding-left">© 2014 商之联.</p>
</footer>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}polyfill/rem.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}polyfill/respond.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}amazeui.legacy.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="{:C('SUPPLIER_ADMIN_JS')}jquery.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}amazeui.min.js"></script>
 <!--<![endif]-->  <!--<![endif]-->
<script src="{:C('SUPPLIER_ADMIN_JS')}app.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}laydate/laydate.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}jquery.cookie.js"></script>
<script type="text/javascript">
	var ajaxsearch=function(page)
	{
		//获取搜索条件
		var page = arguments[0]?arguments[0] : 1;
		var $ordersn=$("input[name='ordersn']").val();
		var $starttime=$("#start").val();
    var $endtime=$("#end").val();    //$("select option:selected").val();
    var $areatype=$("select[name='areatype'] option:selected").val();
    var $paytype=$("select[name='paytype'] option:selected").val();
		var $orderstatus=$("select[name='orderstatus'] option:selected").val();
    var $shopid=$("select[name='shopid'] option:selected").val();
		$.ajax(
		{
			type:'POST',
			url:"{:U('Order/searchOrder')}",
			data:{"ordersn":$ordersn,'starttime':$starttime,'paytype':$paytype,"areatype":$areatype,"endtime":$endtime,"orderstatus":$orderstatus,"page":page,"shopid":$shopid},
			dateType:'JSON',
			success:function(result)
			{	
				var result=jQuery.parseJSON(result);
				
				  var $page=result.pagearr; //底部分页
          var $orders=result.orders;//订单
          var $tbody=$('<tbody></tbody>');
          var $string='';
        if (result.status)
				{
					
					$.each($orders,function(key,order){
						//console.log(value.companyname+key);
						$string+="<tr>";
            $string+='<td><input type="checkbox" name="subBox" value='+order.orderid +"</td>";
						$string+="<td>"+order.orderid +"</td>";
						$string+="<td>"+order.order_sn+"</td>";
						$string+="<td>"+order.number +"</td>";
						$string+="<td>"+order.price +"</td>";
						$string+="<td>"+order.supperprice +"</td>";
            
						$string+="<td>"+order.pay_type +"</td>"; 
						$string+="<td>"+order.companyname +"</td>";
						$string+="<td>"+order.create_time +"</td>";
            $string+="<td>"+order.allstatus +"</td>";
            $string+="<td>"+order.area +"</td>";
            $string+="<td><span class='am-icon-pencil-square-o'></span><a href=__URL__/detail/orderid"+order.orderid+">详情</td>";
						$string+="</tr>";	
					});
					$tbody.append($string);
					$($tbody).replaceAll(".ordertable tbody");

					//替换分页
					$(".count").html($page.count);
					$(".currentpage").html($page.page);
					$("#pagesize").val($page.pagesize);
					$('.prepage').attr('value',$page.prevpage);
					$('.nexpage').attr('value', $page.nextpage);
					$('.laspage').attr('value',$page.pagetotal);
				}else
				{
					 $tbody.append(result.message);
					$($tbody).replaceAll('.ordertable tbody');
				}
			}

    });
  }

  $('#search').click(function(){
      ajaxsearch();
     event.preventDefault();
  });
  //翻页事件
  function pageajax(name){
     var pagevalue=$('.'+name).attr('value');
     ajaxsearch(pagevalue);
    return false;
  }
    
//日期插件

var start = {
    elem: '#start',
    format: 'YYYY-MM-DD hh:mm:ss',
    min: '1999-06-16 23:59:59', //设定最小日期为当前日期
    max: '2099-06-16 23:59:59', //最大日期
    istime: true,
    istoday: false,
    choose: function(datas){
         end.min = datas; //开始日选好后，重置结束日的最小日期
         end.start = datas //将结束日的初始值设定为开始日
    }
};
var end = {
    elem: '#end',
    format: 'YYYY-MM-DD hh:mm:ss',
    min: '1999-06-16 23:59:59',
    max: '2099-06-16 23:59:59',
    istime: true,
    istoday: false,
    choose: function(datas){
        start.max = datas; //结束日选好后，重置开始日的最大日期
    }
};
laydate(start);
laydate(end);
	//导出订单
  $(function(){
      $('.putcsv').click(function(){
          //获取所有选中订单
           var orderids="";
            $("input[name='subBox']:checkbox").each(function()
            { 
                if($(this).prop("checked"))
                {
                    orderids += $(this).val()+","
                }
            })
            
         window.open("__URL__/putCsv?orderids="+orderids);
          
      });
  });
  //全选 
 $(function() {
           $("#checkAll").click(function() {
                $('input[name="subBox"]').prop("checked",this.checked); 
            });
            var $subBox = $("input[name='subBox']");
            $subBox.click(function(){
                $("#checkAll").prop("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false);
            });
        }); 
</script>
<script type="text/javascript">
  $(document).on('click','.delorder',function(){
        var res=confirm("确定删除订单");
        if(!res){
          return false;
        }
        var id=$(this).attr('value');
        $.ajax( {
            type:"GET",
            data:{"orderid":id},
            url: "{:U('Order/delOrder','' )}",
            dataType:"json",
            success:function(message){
                if (message.status)
                {
                    alert(message.msg);
                    location.reload();
                 }else{
                 alert(message.msg);
                  location.reload();
                }
                }


</script>
<script type="text/javascript">
  $(function(){
       var modultname="Order";

       $('.'+modultname).addClass('am-in');
});
</script>
</body>
</html>
